
#include "process.h"
#include<string.h>
#include<unistd.h>
#include<stdio.h>
#define LENGTH 101
#define LABLE '#'

void FlushProcess(double target,double current)
{
    const char* symb="|/-\\";
    static int index=0;
    int len = strlen(symb);
    double rate =( current/target)*100;
    int cnt = (int)rate;
    char bar[LENGTH];

    memset(bar,'\0',sizeof(bar));
    
    for(int i=0; i<cnt; i++)
        bar[i]=LABLE;

        printf("[%-100s][%.1lf%%][%c]\r",bar,rate,symb[index++]);
        index%=len;
        fflush(stdout);
    
    if(rate == 100.0)
        printf("\n");
    

}



void Process()
{
    const char* symb="|/-\\";
    char bar[LENGTH];
    int s_len=strlen(symb);
    memset(bar,'\0',sizeof(bar));

    int cnt=0;
    while(cnt<=100)
    {
        printf("[%-100s][%d%%][%c]\r",bar,cnt,symb[cnt%s_len]);
        fflush(stdout);
        bar[cnt++]=LABLE;
        sleep(1);
    }
    printf("\n");

}

